package june.test_6_20;

import java.util.Scanner;

public class TestMain3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int count = 0;
        int[][] arr = new int[n][4];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 4; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        while (A > 0 && B > 0 && C > 0) {
            boolean bo = true;
            int max = 0;
            int tmp = 0;
            for (int i = 0; i < n; i++) {
                if(arr[i][3] > max) {
                    max = arr[i][3];
                    tmp = i;
                    bo = false;
                }
            }
            if(bo) {
                break;
            }
            if(A >= arr[tmp][0] && B >= arr[tmp][1] && C >= arr[tmp][2]) {
                A -= arr[tmp][0];
                B -= arr[tmp][1];
                C -= arr[tmp][2];
                count += arr[tmp][3];
            }
            arr[tmp][3] = -1;
        }
        System.out.println(count);
    }
}
